﻿<?php

$id=$_GET['id'];
$obj=new mysql($config);
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
  $sql="select * from `cate` where `pid`=$id";
  $date=$obj->getOne($sql);
   echo !empty($date)?1:0;
   die;
}




	$sql="select * from `cate`";
	$date=$obj->getCondition($sql);
	
	function delCate($id,$date){
		static $arr=array();
	     foreach ($date as $k => $v) {
	     	if($v['pid']==$id){
	            $arr[]=$v['id'];
	            delCate($v['id'],$date);
	     	}
	     }
        return $arr;
	}

$id_list=delCate($id,$date);
$id_list[]=$id;
$row=$obj->delete($id_list,'cate');


if($row>0){
 echo '<script>alert("删除成功");history.go(-1);</script>';
}else{
 echo '<script>alert("删除失败");history.go(-1);</script>';
}